<template>
  <div class="pie-main">
    <div id="pie-echart" />
  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: 'PieEchart',

  data() {
    return {

    }
  },

  mounted() {
    this.init()
  },

  methods: {
    init() {
      const PieEchart = echarts.init(document.getElementById('pie-echart'))
      const option = {
        title: {
          text: '购买终端',
          textStyle: {
            color: '#97a5d0',
            fontSize: 26,
            fontWeight: 'normal'
          }
        },
        series: [
          {
            name: 'Nightingale Chart',
            type: 'pie',
            radius: [60, 110],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 0
            },
            data: [
              {
                value: 50,
                name: 'Android',
                itemStyle: {
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: '#6d48dc' // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: '#6d48dc' // 100% 处的颜色
                      }
                    ],
                    global: false // 缺省为 false
                  }
                },
                label: {
                  color: '#6d48dc'
                }
              },
              {
                value: 40,
                name: 'iOS',
                itemStyle: {
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: '#24c7ff' // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: '#2490ff' // 100% 处的颜色
                      }
                    ],
                    global: false // 缺省为 false
                  }
                },
                label: {
                  color: '#2490ff'
                }
              },
              {
                value: 30,
                name: 'PC Web',
                itemStyle: {
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: '#bd00ff' // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: '#cd00ff' // 100% 处的颜色
                      }
                    ],
                    global: false // 缺省为 false
                  }
                },
                label: {
                  color: '#cd00ff'
                }
              },
              {
                value: 20,
                name: 'Wep Web',
                itemStyle: {
                  color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                      {
                        offset: 0,
                        color: '#881d89' // 0% 处的颜色
                      },
                      {
                        offset: 1,
                        color: '#72208e' // 100% 处的颜色
                      }
                    ],
                    global: false // 缺省为 false
                  }
                },
                label: {
                  color: '#72208e'
                }
              }
            ]
          }
        ]
      }

      PieEchart.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped>
.pie-main{
  width: 100%;
  height: 100%;
  #pie-echart{
    width: 100%;
    height: 100%;
  }
}
</style>
